package com.gjy.stream;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2022-12-12 15:11:13
 */
public class T2Test {

    @Test
    public void test1() {
        B b1 = new B("2022-12-12");
        B b2 = new B("2022-12-11");
        B b3 = new B("2022-12-10");
        B b4 = new B("2022-12-01");
        B b5 = new B("2022-12-02");
        B b6 = new B("2022-12-03");
        B b7 = new B("2022-12-05");
        B b8 = new B("2022-12-07");
        B b9 = new B("2022-12-08");
        B b10 = new B("2022-12-09");

        List<B> bs = Arrays.asList(b1, b2, b3, b4, b5, b6, b7, b8, b9, b10);

        List<A> as = Arrays.asList(new A("a", bs), new A("b", bs), new A("c", bs));

        as.forEach(a -> a.setBs(a.getBs().stream()
                .sorted(Comparator.comparing(B::getDatetime).reversed())
                .collect(Collectors.toList())));

//        as.forEach(System.out::println);

//        A a = as.stream()
//                .max(Comparator.comparing(A::getName))
//                .get();
//        System.out.println(a);

        B b = bs.stream()
                .min(Comparator.comparing(B::getDatetime))
                .get();
        System.out.println(b);
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    private static class A {
        private String name;
        private List<B> bs;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    private static class B {
        private String datetime;
    }
}
